/*     */ package com.umeng.newxp.view;
/*     */ 
/*     */ import android.content.Context;
/*     */ import android.os.Handler;
/*     */ import android.view.View;
/*     */ import android.view.ViewGroup.LayoutParams;
/*     */ import com.umeng.common.Log;
/*     */ import com.umeng.common.c;
/*     */ import com.umeng.newxp.Promoter;
/*     */ import com.umeng.newxp.common.g;
/*     */ import com.umeng.newxp.controller.ExchangeDataService;
/*     */ import com.umeng.newxp.controller.XpListenersCenter.InitializeListener;
/*     */ import com.umeng.newxp.net.XpReportClient;
/*     */ import com.umeng.newxp.net.e;
/*     */ import com.umeng.newxp.net.e.a;
/*     */ import com.umeng.newxp.view.widget.SwipeView;
/*     */ import com.umeng.newxp.view.widget.SwipeViewPointer;
/*     */ import com.umeng.newxp.view.widget.a;
/*     */ import com.umeng.newxp.view.widget.a.b;
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ public class GridTemplate
/*     */ {
/*  42 */   private static final String a = GridTemplate.class.getName();
/*     */   public View contentView;
/*     */   private SwipeViewPointer b;
/*     */   private List<Promoter> c;
/*     */   private Context d;
/*     */   private List<a.b> e;
/*     */   private SwipeView f;
/*     */   private ExchangeDataService g;
/*     */   private int h;
/*     */   private GridTemplateConfig i;
/*  55 */   private Map<Integer, a> j = new HashMap();
/*     */ 
/*     */   public GridTemplate(List<Promoter> paramList, ExchangeDataService paramExchangeDataService, Context paramContext, GridTemplateConfig paramGridTemplateConfig)
/*     */   {
/*  60 */     if ((paramList != null) && (paramList.size() > 0)) {
/*  61 */       this.c = new ArrayList();
/*  62 */       this.c.addAll(paramList);
/*     */     }
/*     */ 
/*  65 */     this.d = paramContext;
/*  66 */     this.g = paramExchangeDataService;
/*  67 */     this.i = (paramGridTemplateConfig == null ? new GridTemplateConfig() : paramGridTemplateConfig);
/*     */ 
/*  69 */     this.h = paramExchangeDataService.layoutType;
/*     */ 
/*  71 */     this.contentView = e();
/*     */ 
/*  73 */     if ((this.c != null) && (this.c.size() > 0)) {
/*  74 */       b();
/*     */     } else {
/*  76 */       this.g.sessionId = "";
/*  77 */       this.g.requestDataAsyn(this.d, new Y(this));
/*     */     }
/*     */   }
/*     */ 
/*     */   public void changed()
/*     */   {
/*  90 */     Set localSet = this.j.keySet();
/*  91 */     for (Integer localInteger : localSet)
/*  92 */       ((a)this.j.get(localInteger)).a(true);
/*     */   }
/*     */ 
/*     */   private void b()
/*     */   {
/*  97 */     if (this.g.initializeListener != null) this.g.initializeListener
/*  98 */         .onReceived(this.c == null ? 0 : this.c.size());
/*  99 */     this.e = a(this.c, 0, this.c == null ? 0 : this.c.size(), 0);
/*     */     try {
/* 101 */       a.b localb = (a.b)this.e.get(0);
/* 102 */       a(localb.a, localb.d, localb.c);
/*     */     } catch (Exception localException) {
/* 104 */       Log.b(a, "can`t send init page report ", localException);
/*     */     }
/* 106 */     c();
/* 107 */     if (this.i.c) requestNextPage(); 
/*     */   }
/*     */ 
/*     */   public GridTemplate(List<Promoter> paramList, ExchangeDataService paramExchangeDataService, Context paramContext)
/*     */   {
/* 111 */     this(paramList, paramExchangeDataService, paramContext, null);
/*     */   }
/*     */ 
/*     */   public void notifyTotalDataChanged() {
/* 115 */     a.b localb1 = (a.b)this.e.get(this.e.size() - 1);
/*     */ 
/* 117 */     int k = 0;
/* 118 */     if (this.e.size() == 1) {
/* 119 */       k = ((a.b)this.e.get(0)).d;
/*     */     }
/*     */ 
/* 122 */     if (localb1.d + 1 >= this.c.size()) {
/* 123 */       Log.c(a, "No data update....");
/* 124 */       localb1.e = true;
/*     */     }
/*     */     else {
/* 127 */       int m = 0;
/* 128 */       if (localb1.b < this.i.maxPsize)
/*     */       {
/* 130 */         int n = this.i.maxPsize - localb1.b;
/* 131 */         int i1 = this.c.size();
/*     */ 
/* 133 */         int i2 = localb1.d + n;
/* 134 */         if (i2 < i1) {
/* 135 */           localb1.d = i2;
/* 136 */           localb1.e = true;
/*     */         } else {
/* 138 */           localb1.d = (i1 - 1);
/*     */         }
/* 140 */         localb1.b = (localb1.d - localb1.a + 1);
/* 141 */         localb1.f = true;
/*     */       }
/* 143 */       m = localb1.d + 1;
/*     */ 
/* 145 */       if ((this.e.size() <= 0) || (this.i.c))
/*     */       {
/* 147 */         List localList = a(this.c, m, this.c.size(), 
/* 148 */           localb1.c + 1);
/* 149 */         if (localList != null) for (a.b localb3 : localList) {
/* 150 */             this.e.add(localb3);
/*     */           }
/*     */ 
/*     */       }
/*     */ 
/*     */     }
/*     */ 
/* 157 */     a.b localb2 = (a.b)this.e.get(0);
/* 158 */     if ((k > 0) && (k < localb2.d)) {
/* 159 */       a(k + 1, localb2.d, localb2.c);
/*     */     }
/*     */ 
/* 162 */     Log.c(a, "new PageSize " + this.e.size() + " show size :" + d() + " ");
/*     */ 
/* 164 */     c();
/*     */   }
/*     */ 
/*     */   private void c() {
/* 168 */     for (int k = 0; k < this.e.size(); k++) {
/* 169 */       a.b localb = (a.b)this.e.get(k);
/*     */ 
/* 171 */       if (localb.e)
/*     */       {
/*     */         a locala;
/* 173 */         if (this.j.containsKey(Integer.valueOf(localb.c))) {
/* 174 */           locala = (a)this.j.get(Integer.valueOf(localb.c));
/* 175 */           if (localb.f) {
/* 176 */             locala.a(false);
/* 177 */             localb.f = false;
/*     */           }
/*     */         } else {
/* 180 */           locala = (a)a(this.d, localb);
/* 181 */           locala.setLayoutParams(new ViewGroup.LayoutParams(-1, -1));
/* 182 */           this.j.put(Integer.valueOf(localb.c), locala);
/* 183 */           this.f.addView(locala);
/*     */ 
/* 185 */           if (this.i.d)
/* 186 */             if (this.f.getPageControl() != null) this.f.getPageControl()
/* 187 */                 .addPageCount(1);
/*     */             else
/* 189 */               this.f.setPageControl(this.b);
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   private int d()
/*     */   {
/* 198 */     int k = 0;
/* 199 */     for (a.b localb : this.e) {
/* 200 */       if (localb.e) k++;
/*     */     }
/* 202 */     return k;
/*     */   }
/*     */ 
/*     */   private List<a.b> a(List<Promoter> paramList, int paramInt1, int paramInt2, int paramInt3)
/*     */   {
/* 216 */     ArrayList localArrayList = new ArrayList();
/* 217 */     if ((paramInt1 > 0) && (!this.i.c) && (paramList == null)) {
/* 218 */       return localArrayList;
/*     */     }
/* 220 */     int k = paramList == null ? 0 : paramList.size();
/* 221 */     int m = paramInt2 - paramInt1 < k ? paramInt2 - paramInt1 : k;
/*     */ 
/* 223 */     int n = m % this.i.maxPsize == 0 ? m / this.i.maxPsize : m / this.i.maxPsize + 1;
/*     */ 
/* 225 */     int i1 = paramInt1;
/* 226 */     int i2 = paramInt2 - 1;
/* 227 */     for (int i3 = 0; i3 < (this.i.c ? n : 1); i3++) {
/* 228 */       int i4 = i2 - (i1 + this.i.maxPsize - 1);
/* 229 */       a.b localb2 = new a.b(i1, i4 < 0 ? this.i.maxPsize + i4 : 
/* 230 */         this.i.maxPsize);
/* 231 */       localArrayList.add(localb2);
/* 232 */       localb2.c = (paramInt3 + i3);
/* 233 */       i1 = localb2.d + 1;
/* 234 */       localb2.e = true;
/*     */     }
/*     */ 
/* 238 */     if (((paramInt3 > 0) && (localArrayList.size() > 0)) || (localArrayList.size() > 1)) {
/* 239 */       a.b localb1 = (a.b)localArrayList.get(localArrayList.size() - 1);
/* 240 */       if (localb1.b < this.i.maxPsize) localb1.e = false;
/*     */     }
/*     */ 
/* 243 */     return localArrayList;
/*     */   }
/*     */ 
/*     */   private View e() {
/* 247 */     View localView = View.inflate(this.d, 
/* 248 */       c.a(this.d).e("umeng_xp_handler_gallery"), null);
/*     */ 
/* 250 */     this.f = ((SwipeView)localView.findViewById(c.a(this.d).c(
/* 251 */       "umeng_xp_gallery")));
/*     */ 
/* 253 */     this.f.setOnPageChangedListener(new Z(this));
/*     */ 
/* 268 */     this.b = ((SwipeViewPointer)localView.findViewById(c.a(this.d).c(
/* 269 */       "umeng_xp_gallery_page_pointer")));
/*     */ 
/* 271 */     if (this.i.d) {
/* 272 */       this.b.setVisibility(0);
/* 273 */       if (this.i.a != null) this.b.setActiveDrawable(this.i.a);
/* 274 */       if (this.i.b != null) this.b
/* 275 */           .setInactiveDrawable(this.i.b); 
/*     */     }
/* 277 */     else { this.b.setVisibility(8); }
/*     */ 
/* 279 */     return localView;
/*     */   }
/*     */ 
/*     */   private void a(int paramInt1, int paramInt2, int paramInt3)
/*     */   {
/* 284 */     int k = paramInt2 - paramInt1 + 1;
/* 285 */     ArrayList localArrayList = new ArrayList();
/* 286 */     for (int m = 0; m < k; m++) {
/*     */       try {
/* 288 */         localArrayList.add((Promoter)this.c.get(paramInt1 + m));
/* 289 */         Log.c(a, "Report :" + ((Promoter)this.c.get(paramInt1 + m)).title);
/*     */       } catch (Exception localException) {
/* 291 */         Log.b(a, "report error ", localException);
/*     */       }
/*     */     }
/* 294 */     Log.c(a, "============" + paramInt3 + "=============");
/* 295 */     if (localArrayList.size() > 0) {
/* 296 */       e locale = new e.a(this.d)
/* 297 */         .a(0).b(paramInt3)
/* 298 */         .d(this.g.getTimeConsuming()).d(3)
/* 299 */         .c(this.g.layoutType)
/* 300 */         .a((Promoter[])localArrayList.toArray(new Promoter[0])).b(g.a(this.d, this.g)).a(this.g.slot_id)
/* 301 */         .c(this.g.sessionId).a();
/* 302 */       new XpReportClient(this.d).sendAsync(locale, null);
/*     */     } else {
/* 304 */       Log.b(a, "report error no promoter need report.");
/*     */     }
/*     */   }
/*     */ 
/*     */   private View a(Context paramContext, a.b paramb) {
/* 309 */     aa localaa = new aa(this, this.c, paramb, paramContext);
/*     */ 
/* 351 */     a locala = new a(paramContext, localaa, this.i);
/* 352 */     locala.setLayoutParams(new ViewGroup.LayoutParams(-1, -1));
/*     */ 
/* 354 */     return locala;
/*     */   }
/*     */ 
/*     */   public void requestNextPage() {
/* 358 */     new Handler().postDelayed(new ac(this), 
/* 377 */       300L);
/*     */   }
/*     */ 
/*     */   public void debugNextPage(List<Promoter> paramList) {
/* 381 */     this.c.addAll(paramList);
/* 382 */     notifyTotalDataChanged();
/* 383 */     Log.c(a, "Total Data changed " + this.c.size());
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\umeng_sdk.jar
 * Qualified Name:     com.umeng.newxp.view.GridTemplate
 * JD-Core Version:    0.6.2
 */